$(function(){
		$(".search_table").hide();
		$(".salary_update_cal").hide();
		
		$(".search_btn").click(function(){
			$(".search_table").hide();
			$(".search_table").fadeIn(500);
			$.ajax({
				type : "GET",
				url : "resources/youxiao/js/salary_item.JSON",
				success : function(data) {
					console.log(data);
					var jsonData = eval('(' + data + ')');
					ajax_load_table(jsonData);
				}
			});
		});

		var ajax_load_table = function(jsonData){	
			var html;
			$.each(jsonData,function(i){
				var salary=jsonData[i];
				html += 
					"<tr> " +
						"<td><a href='#'>"+salary.itemName+"</a></td> " +
						"<td>"+salary.itemType+"</td>" +
						"<td class='hidden-480'>"+salary.itemShow+"</td>" +
						"<td>"+salary.itemCalculate+"</td>" +
						"<td>"+salary.itemOrder+"</td>" +
						"<td>"+salary.itemAdd+"</td> " +
						"<td>" +
							"<div class='hidden-sm hidden-xs btn-group'>" +
									"<button class='btn btn-xs btn-info salary_item_update_btn'>" +
											"<i class='ace-icon fa fa-pencil bigger-120'></i>" +
									"</button>" +
									"<button class='btn btn-xs btn-danger salary_item_delete_btn'>" +
											"<i class='ace-icon fa fa-trash-o bigger-120'></i>" +
									"</button>";
				if(salary.itemType=="计算项目"){
						html+=		"<button class='btn btn-xs btn-warning salary_item_update_cal_btn'> " +
											"<i class='ace-icon fa fa-flag bigger-120'></i>" +
									"</button>";
				}
					html+=	"</div>" +
						"</td>" +
					"</tr> ";
			});
			console.log(html);
			$(".search_container").html("");
			$(".search_container").html(html);
			
			$(".salary_item_update_btn").on("click",function() {
				$('.salary_update_modal').modal('toggle');
				$(".salary_update_type").on("change",function(){
					var item_type = $(".salary_update_type option:selected").val();
					if(item_type == "计算项目")
						$(".salary_update_cal").show();
					else
						$(".salary_update_cal").hide();
				});
			});
			
			$(".salary_item_delete_btn").on("click",function() {
				$('.salary_delete_modal').modal('toggle');
			});
			
			$(".salary_item_update_cal_btn").on("click",function() {
				$('.salary_update_cal_modal').modal('toggle');
			});
		};

		$(".salary_add_cal").hide();
		$(".salary_item_add_btn").on("click",function() {
			$('.salary_add_modal').modal('toggle');
			$(".salary_add_type").on("change",function(){
				var item_type = $(".salary_add_type option:selected").val();
				if(item_type == "计算项目")
					$(".salary_add_cal").show();
				else
					$(".salary_add_cal").hide();
			});
		});
		
})